//
//  MSRegistSuccessTableVC.m
//  SocietySale
//
//  Created by yumingwei on 2016/11/27.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSRegistSuccessTableVC.h"

@interface MSRegistSuccessTableVC ()
//section头部标题
@property(nonatomic,copy)NSArray *sectionTitleArray;

@end

@implementation MSRegistSuccessTableVC

- (void)viewDidLoad{
    [super viewDidLoad];
    self.sectionTitleArray = @[@"审核通过后你将获得",@"分享至朋友圈,获得额外7天高级会员资格"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellId = @"cellId";
    MSRegistSuccessCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[MSRegistSuccessCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 25;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    bgView.backgroundColor = [UIColor whiteColor];
    
    CGSize size = [HDUtil getSizeWithText:self.sectionTitleArray[section] font:HeitiFont(12)];
    
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-size.width-20)/2-50, 10, size.width+20+100, 0.6)];
    lineLabel.backgroundColor = kNormalGray;
    [bgView addSubview:lineLabel];

    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(lineLabel.left+50, 0, size.width+20, 20);
    label.font = HeitiFont(12);
    label.textColor = kLightGrayColor;
    label.text = self.sectionTitleArray[section];
    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor = [UIColor whiteColor];
    [bgView addSubview:label];
    
    if (section== 1) {
        label.textColor = kLightBlackColor;
    }

    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 30;
    }
    else{
        return 0.01;
    }
}
@end



@interface MSRegistSuccessCell ()
@property (nonatomic, strong) UILabel  *titleLabel;
@property (nonatomic, strong) UILabel  *subLabel;
@end

@implementation MSRegistSuccessCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.titleLabel = [self creatLabel:CGRectMake(50, 0, 150, 28)];
    self.subLabel = [self creatLabel:CGRectMake(75, _titleLabel.bottom+2, 240, 20)];
    self.subLabel.font = HeitiFont(13);
    self.subLabel.textColor =kDarkGrayColor;
}

//创建label
- (UILabel*)creatLabel:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.font = HeitiFont(14);
    label.textColor = [UIColor blackColor];
    [self.contentView addSubview:label];
    return label;
}

- (void)setModel:(MSCommonModel *)model {
    _model = model;
    NSMutableAttributedString *titleAttstr = [[NSMutableAttributedString alloc] initWithString:model.title];
    
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment.bounds = CGRectMake(0, -5.5, 24, 24);
    textAttachment.image = [UIImage imageNamed:model.thirdTitle];
    NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
    [titleAttstr insertAttributedString:attachmentString atIndex:0];
    
    self.titleLabel.attributedText = titleAttstr;
    self.subLabel.text = model.subTitle;
}

@end
